package com.jmpt.fangbohui.ui;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.google.gson.Gson;
import com.jmpt.fangbohui.Constants;
import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.ui.base.BaseHeadActivity;
import com.jmpt.fangbohui.utils.DebugLog;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

/**
 * 
 * ClassName: BrokerPersonNetStoreHomePageActivity
 * date: 2015-8-26 上午10:55:40
 *
 * @author Lee
 * @since JDK 1.7
 */
public class BrokerPersonNetStoreHomePageActivity extends BaseHeadActivity implements OnClickListener{

	private String brokerId = "1812";
	public static final int SUCCESS = 505;
	public static final int FAILED = 404;
	
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			switch(msg.what){
			case SUCCESS:
				String result = (String) msg.obj;
				parser(result);
				break;
			case FAILED:
				
				break;
				
			}
		};
	};
	private ViewPager vp_broker_person_net_store_home_page;
	private ListView lv_broker_person_net_store_home_page;
	private Button btn_more_es;
	private Button btn_more_zf;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_broker_person_net_store_home_page);
		getExtra();
		initView();
		initData();
	}

	private void initView() {
		showTitle("经纪人个人网店首页");
		showBackButton(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		vp_broker_person_net_store_home_page = (ViewPager) findViewById(R.id.vp_broker_person_net_store_home_page);
		lv_broker_person_net_store_home_page = (ListView) findViewById(R.id.lv_broker_person_net_store_home_page);
		btn_more_es = (Button) findViewById(R.id.btn_more_es);
		btn_more_zf = (Button) findViewById(R.id.btn_more_zf);
		btn_more_es.setOnClickListener(this);
		btn_more_zf.setOnClickListener(this);
		
	}

	protected void parser(String result) {
		DebugLog.i(result);
		
		Gson gson = new Gson();
		
	}

	private void getExtra() {
		Intent intent = getIntent();
		brokerId = intent.getStringExtra("brokerId");
		//访问网络
		getDataForNet();
	}

	private void getDataForNet() {
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.GET, Constants.URL.BROKERPERSONNETSTOREHOMEPAGE+"?uid="+brokerId, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Message obtain = Message.obtain();
				obtain.what = FAILED;
				handler.sendMessage(obtain);
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				Message obtain = Message.obtain();
				obtain.what = SUCCESS;
				obtain.obj = arg0.result;
				handler.sendMessage(obtain);
			}
		});

	}

	private void initData() {
		
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch(v.getId()){
		case R.id.btn_more_zf:
			intent = new Intent(this,BrokerPersonNetStoreEsHouse1ListActivity.class);
			intent.putExtra("uid", brokerId);
			startActivity(intent);
			break;
		case R.id.btn_more_es:
			intent = new Intent(this,BrokerPersonNetStoreEsHouse2ListActivity.class);
			intent.putExtra("uid", brokerId);
			startActivity(intent);
			break;
		}
	}
}
